<script>
	import {
		socket
	} from 'utils/socket.js'
	import DB from 'utils/sqlite.js'
	export default {
		onLaunch: function() {
			console.log('App Launch')
			this.url = "http://192.168.1.179:9090/";
			this.wurl = "ws://192.168.1.179:9000/ws";
			if (uni.getStorageSync("token") != null && uni.getStorageSync("token") != "") {
				uni.switchTab({
					url: "/pages/tabBar/list/list"
				})
				socket.constructor(getApp().wurl, 300000, uni.getStorageSync("userId"))
				// 打开数据库
				DB.openSqlite();

				socket.getMessage(res => {
					console.log(JSON.parse(res.data));
				})

			}

		},
		onShow: function() {
			console.log('App Show')
			if (uni.getStorageSync("token") != null && uni.getStorageSync("token") != "") {
				socket.constructor(getApp().wurl, 300000, uni.getStorageSync("userId"))
			}
		},
		onHide: function() {
			console.log('App Hide')
		},
		onExit: function() {
			var msg = {
				uid: uni.getStorageSync("userId"),
				type: 2
			}
			socket.send(JSON.stringify(msg))
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
</style>